import django_filters
from .models import Devices


class DevicesFilter(django_filters.FilterSet):
    """
    设备信息
    """

    alias = django_filters.CharFilter(
        field_name='alias',
        lookup_expr='icontains'
    )

    id = django_filters.NumberFilter(
        field_name='id'
    )


class ControlsFilter(django_filters.FilterSet):
    """
    继电器信息
    """
    devices = django_filters.NumberFilter(
        field_name='devices_id',
        required=True,
    )


class ActionFilter(django_filters.FilterSet):
    # 获取某个devices下的控制组 即控制实例

    devices = django_filters.NumberFilter(
        field_name='devices_id',
        required=True,
    )


class SensorFilter(django_filters.FilterSet):
    # 获取某个devices下的控制组 即控制实例
    devices = django_filters.NumberFilter(
        field_name='devices_id',
        required=True,
    )


class SensorHistoryFilter(django_filters.FilterSet):
    # 获取某个devices下的控制组 即控制实例
    devices = django_filters.CharFilter(
        field_name='devices__alias',
        lookup_expr="icontains",
        required=False,
    )
    devices_id = django_filters.NumberFilter(
        field_name='devices_id',
        required=False,
    )
    time_start = django_filters.NumberFilter(
        field_name='time_ticket',
        lookup_expr="gt",
        required=False,
    )
    time_end = django_filters.NumberFilter(
        field_name='time_ticket',
        lookup_expr="lt",
        required=False,
    )
    sensor = django_filters.NumberFilter(
        field_name='sensor_id',
        required=False,
    )
    mock_sensor = django_filters.NumberFilter(
        field_name='mock_sensor_id',
        required=False,
    )
    number_sensor = django_filters.NumberFilter(
        field_name='number_sensor_id',
        required=False,
    )


class AutoRuleFilter(django_filters.FilterSet):

    devices = django_filters.NumberFilter(
        field_name='devices_id',
        required=True,
    )
    channle = django_filters.NumberFilter(
        field_name='output_channle',
        required=False
    )
    control_type = django_filters.NumberFilter(
        field_name='output_type',
        required=False
    )
    ruletype = django_filters.NumberFilter(
        field_name='time_status',
        required=False
    )


class ControlGroupFilter(django_filters.FilterSet):

    devices = django_filters.NumberFilter(
        field_name='devices_id',
        required=True,
    )


class MockControlGroupFilter(django_filters.FilterSet):

    devices = django_filters.NumberFilter(
        field_name='devices_id',
        required=True,
    )


class DeviceVideoMonitorFilter(django_filters.FilterSet):

    devices = django_filters.NumberFilter(
        'devices_id',
        required=True
    )


class NumberSensorFilter(django_filters.FilterSet):

    devices = django_filters.NumberFilter(
        'devices_id',
        required=True
    )
